import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy


class DXMCAQ:
    url = 'http://127.0.0.1:4723/wd/hub'
    param = {
        "deviceName": "8HJ76H49KJQKM7IF",
        "platformName": "Android",
        "platformVersion": "13",
        "appPackage": "com.duxiaoman.wallet",
        "appActivity": "com.duxiaoman.wallet.home.SplashActivity"
    }

    def apptestcase1(self):
        time.sleep(5)
        driver = webdriver.Remote(self.url, self.param)
        # 点击同意按钮
        el1 = driver.find_element(MobileBy.ID, "com.duxiaoman.wallet:id/protocol_dialog_pos_btn")
        el1.click()
        time.sleep(5)
        # 点击拒绝按钮
        el3 = driver.find_element(MobileBy.XPATH,
            "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.Button[1]")
        el3.click()
        time.sleep(5)
        # 点击查看额度按钮
        el4 = driver.find_element(MobileBy.ID, "com.duxiaoman.wallet:id/rv_second_short_button")
        el4.click()
        time.sleep(5)
        # 填写手机号
        el5 = driver.find_element(MobileBy.XPATH,
            "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.view.View[1]/android.widget.EditText")
        el5.send_keys("18515986713")
        # 点击获取验证码按钮
        el6 = driver.find_element(MobileBy.XPATH,
            "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.view.View[2]/android.widget.Button")
        el6.click()
        # 这里手动输入验证码，所以等待时间稍长
        time.sleep(20)
        # 点击查看我的额度按钮
        el8 = driver.find_element(MobileBy.XPATH,
            "/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[2]/android.view.View/android.view.View/android.view.View/android.view.View[4]/android.widget.TextView[1]")
        el8.click()
        time.sleep(5)
        driver.quit()


apptestcase = DXMCAQ()
apptestcase.apptestcase1()
